﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Workflow.Dto;
using Workflow.IDAO;
using Workflow.IService;
using Workflow.Model;
using Workflow.Model.Enum;

namespace Workflow.Service
{
	public class CaseEEMService :ICaseEEMService
	{
		public ICaseEEMDao CaseDao { get; set; }
		public ICaseEEMLogDao CaseEEMLogDao { get; set; }

		/// <summary>
		/// 所有CaseEEM取得
		/// </summary>
		public IList<CaseEEM> GetAllCaseByPage(out long count, int pageIndex, int pageSize, CaseQueryDto caseQueryDto, string orderBy, string sort)
		{
			return CaseDao.GetAllCaseByPage(out count, pageIndex, pageSize, caseQueryDto, orderBy, sort);
		}

		public IList<FolerClass> GetFolderClass(string parentCode)
		{
			return CaseDao.GetFolderClass(parentCode);
		}


        public IList<CaseEEM> GetCaseByUser(out long count, int pageIndex, int pageSize, CaseQueryDto caseQueryDto, string orderBy, string sort)
        {
         return   CaseDao.GetCaseByUser(out  count, pageIndex,  pageSize, caseQueryDto, orderBy,  sort);
        }

		public IList<CaseEEM> GetAllCase(CaseQueryDto caseQueryDto)
		{
			return CaseDao.GetAllCase(caseQueryDto);
		}

		public CaseEEM GetGaseById(long id)
		{
			return CaseDao.Get(id);
		}

		public void SaveOrUpdateCase(CaseEEM model)
		{
			 CaseDao.SaveOrUpdate(model);

			 CaseEEMLog caseEemLog = new CaseEEMLog();
			 caseEemLog.CaseNo = model.CaseNo;
			 caseEemLog.StatusDate = model.StatusDate;
			 if (model.WorkStatus.WorkStatusCode == ((int)EnumWorkStatus.Closed).ToString())
			 {
				 caseEemLog.StatusOperator = model.Operator;
			 }
			 else
			 {
				 caseEemLog.StatusOperator = model.StatusOperator;
			 }
			 caseEemLog.WorkStatus = model.WorkStatus;
			 caseEemLog.CommentCode = model.CommentCode;

			 CaseEEMLogDao.SaveOrUpdate(caseEemLog);
		}
		public void SaveOrUpdateCaseNoLog(CaseEEM model)
		{
			CaseDao.SaveOrUpdate(model);

		}

		/// <summary>
		/// 操作的下一个CaseEEM
		/// </summary>
		/// <param name="caseNo"></param>
		/// <param name="userid"></param>
		/// <returns></returns>
		public CaseEEM GetNextGase(long caseNo, long userid, string workStatus)
		{
			return CaseDao.GetNextGase(caseNo, userid, workStatus);

		}
		public IList<EEMCaseMonitorDto> GetCaseMonitor(CaseMonitorQueryDto caseMonitorQueryDto)
		{
			return CaseDao.GetCaseMonitor(caseMonitorQueryDto);
		}
		public IList<EEMPAMonitorDto> GetPAMonitor(PAMonitorQueryDto caseMonitorQueryDto)
		{
			return CaseDao.GetPAMonitor(caseMonitorQueryDto);
		}

		public IList<CycleTimeReportDto> GetCycleTimeReport(ReceivedCaseDayReportQueryDto ReceivedCaseDayReportQueryDto)
		{
			DateTime tempto = DateTime.Parse(ReceivedCaseDayReportQueryDto.ToDay);
			ReceivedCaseDayReportQueryDto.ToDay = tempto.AddDays(1).ToString("yyyy/MM/dd");

			return CaseDao.GetCycleTimeReport(ReceivedCaseDayReportQueryDto);
		}
		
		public IList<ReceivedCaseDayReportEEMDto> GetReceivedCaseDayReportEEM(ReceivedCaseDayReportQueryDto ReceivedCaseDayReportQueryDto)
		{
			DateTime tempto = DateTime.Parse(ReceivedCaseDayReportQueryDto.ToDay);
			ReceivedCaseDayReportQueryDto.ToDay = tempto.AddDays(1).ToString("yyyy/MM/dd");

			return CaseDao.ReceivedCaseDayReportEEM(ReceivedCaseDayReportQueryDto);
		}

		public IList<ReceivedCaseDayReportEEMDto> GetReceivedCaseMonthReportEEM(ReceivedCaseDayReportQueryDto ReceivedCaseDayReportQueryDto)
		{
			DateTime tempto = DateTime.Parse(ReceivedCaseDayReportQueryDto.ToDay);
			ReceivedCaseDayReportQueryDto.ToDay = tempto.AddDays(1).ToString("yyyy/MM/dd");

			return CaseDao.ReceivedCaseMonthReportEEM(ReceivedCaseDayReportQueryDto);
		}
		public IList<UserWorkloadReportEEMDto> GetUserWorkloadReportEEM(ReceivedCaseDayReportQueryDto ReceivedCaseDayReportQueryDto)
		{
			DateTime tempto = DateTime.Parse(ReceivedCaseDayReportQueryDto.ToDay);
			ReceivedCaseDayReportQueryDto.ToDay = tempto.AddDays(1).ToString("yyyy/MM/dd");

			return CaseDao.GetUserWorkloadReportEEM(ReceivedCaseDayReportQueryDto);
		}

		public IList<FirstPassYeildReportEEMDto> GetFirstPassYeildReportEEM(ReceivedCaseDayReportQueryDto ReceivedCaseDayReportQueryDto)
		{

			DateTime tempto = DateTime.Parse(ReceivedCaseDayReportQueryDto.ToDay);
			ReceivedCaseDayReportQueryDto.ToDay = tempto.AddDays(1).ToString("yyyy/MM/dd");

			return CaseDao.GetFirstPassYeildReportEEM(ReceivedCaseDayReportQueryDto);
		}
		public IList<ReasonReportEEMDto> GetReasonReportEEM(ReceivedCaseDayReportQueryDto ReceivedCaseDayReportQueryDto)
		{

			DateTime tempto = DateTime.Parse(ReceivedCaseDayReportQueryDto.ToDay);
			ReceivedCaseDayReportQueryDto.ToDay = tempto.AddDays(1).ToString("yyyy/MM/dd");

			return CaseDao.GetReasonReportEEM(ReceivedCaseDayReportQueryDto);
		}

		public IList<BaseDataReportEEMDto> GetBaseDataReportEEM(CaseQueryDto caseQueryDto)
		{
			return CaseDao.GetBaseDataReportEEM(caseQueryDto);
		}

		public IList<CycleTimeNewReportDto> GetCycleTimeNewReport(ReceivedCaseDayReportQueryDto ReceivedCaseDayReportQueryDto)
		{
			DateTime tempto = DateTime.Parse(ReceivedCaseDayReportQueryDto.ToDay);
			ReceivedCaseDayReportQueryDto.ToDay = tempto.AddDays(1).ToString("yyyy/MM/dd");

			return CaseDao.GetCycleTimeNewReport(ReceivedCaseDayReportQueryDto);
		}
	}
}
